package networking.assignments;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server2 {
	public static void main(String[] args) throws IOException,
			ClassNotFoundException {
		ServerSocket ss = new ServerSocket(1811);
		System.out.println("Server waiting for client to respond....");

		Socket s = ss.accept();
		System.out.println("Connection established with Client");

		Credentials ref = new Credentials("TechM", "ESG");

		ObjectInputStream in = new ObjectInputStream(s.getInputStream());
		Object obj = in.readObject();
		Credentials log = (Credentials) obj;

		DataOutputStream out = new DataOutputStream(s.getOutputStream());
		if (ref.equals(log))
			out.writeUTF("Login Success.");
		else
			out.writeUTF("Login Failure.");

		out.flush();
		in.close();
		out.close();
		s.close();
		ss.close();
	}
}
